<?php
    // includes
	include 'config.php';
    include 'includes/config.php';
    include 'includes/webservice.php';
    include 'includes/xml.php';
    include 'includes/funcoes.php';
    include 'includes/retorno.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
    <?php

        try{
            // instâncias
            $funcoes = new Funcoes();
            $retorno = new Retorno($bd_ingres);
            
            $tipo = isset($_GET['tipo']) ? $_GET['tipo']:'';			
            
            //envio de solicitações de guias
            $clientSoap = new Webservice('tissSolicitacaoProcedimento'); 
            
            if($tipo == 1) include 'solicitacao_internacao.php';
            if($tipo == 2) include 'solicitacao_procedimentos.php';       
            if($tipo == 3) include 'solicitacao_vinculada_internacao.php';
            if($tipo == 4) include 'solicitacao_prorrogacao.php';
            
             
        } catch (Exception $exc) {
            echo '*** Erro Exception : <pre>'.print_r($exc).'</pre> *** </br>';
            echo $exc->faultstring;
        }
        
        
        odbc_close($bd_ingres);
        
        //destruir objetos
        unset($funcoes);
        unset($retorno);
        unset($clientSoap);
        
    ?>
    
    <?php // só fecha a janela se for executado pelo servidor no servidor
    $ip = $_SERVER["REMOTE_ADDR"];    
    if($ip == '127.0.0.1'){ ?>
    <script>
        setTimeout(function(){ window.close(); }, 30000);
    </script>
    <?php } ?>
            
    </body>
</html>

